package com.szrt.javaweb.oa.employee.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.szrt.javaweb.oa.employee.entity.EmployeeEntity;
import com.szrt.javaweb.oa.employee.service.EmployeeService;

@Controller
@RequestMapping("/employee")
public class EmployeeController {
	
	@Autowired
	private EmployeeService service;
	
	
	@RequestMapping(value="/login",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> login(EmployeeEntity entity){
		Map<String,Object> map = new HashMap<String,Object>();
		service.loginCheck(entity, map);
		return map;
		
	}
	
	
	/**
	 * 不分页
	 * @return
	 */
	@RequestMapping(value="/findAll")
	@ResponseBody
	public Map<String,Object> findAll(){
		Map<String,Object> map = new HashMap<String,Object>();
		service.findAll(map);
		return map;
		
	}
	
	
	/**
	 * 分页  
	 * 
	 * 1:告诉前台我数据库中一种有多少条记录
	 * 2:告诉前台我给的是第几页的数据 并且告诉前台这一页有多少条
	 * 
	 * pageNumber page  第几页  默认是第一页 1
	 * pageSize   rows  一页有多少条数据    3
	 * 
	 *  -- limit 0,3       求0= 3*(1-1)
  		-- limit 3,3     求3= 3*(2-1)
  						  pageSize*(pageNumber-1)
  						
  
	 * findAllPage
	 * @return
	 */
	@RequestMapping(value="/findAllPage")
	@ResponseBody
	public Map<String,Object> findAllPage(Integer page,Integer rows){
		
		Integer pageNumber = page;
		Integer pageSize   = rows;
		
		Integer before =pageSize*(pageNumber-1) ;
		Integer after  =pageSize;
		
		
		//用来封装分页的数据  并且把这个数据传递给servcie
		Map<String,Integer> fenye=new HashMap<String,Integer>();
		
		fenye.put("before", before);
		fenye.put("after", after);
		
		
		
		
		System.out.println(pageNumber + " : "+ pageSize);
		
		//用来接收Service执行查询之后返回的结果
		Map<String,Object> reuslt = new HashMap<String,Object>();
		service.findAllPage(fenye,reuslt);
		return reuslt;
		
	}
	
	
	

}
